package vn.sunnet.backviet01.game.coloa.animated.skill;

import org.anddev.andengine.entity.sprite.BaseSprite;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
public class SkillLoiQuangDien extends AnimatedSkill {
	private static final long[] duration = {150, 150, 150, 150};
	public static final String TAG_LNH = "Loi Quang Dien";
	
	private boolean isAttak = false;
	private boolean isCheck = false;
	
	private float damage = 0;
	private float useMana = 0;
	
	private long start = 0;
	
	public SkillLoiQuangDien(int name, float pX, float pY,
			TiledTextureRegion pTiledTextureRegion) {
		super(name, pX, pY, pTiledTextureRegion);
		this.setPosition(pX - 64, pY - 240);
		this.animate(duration);
		start = System.currentTimeMillis();
	}

	public void onManagedUpdate(float pSecondsElapsed) {
		long currentTime = System.currentTimeMillis();
		if (currentTime > start + 700) {
			this.setVisible(false);
		}
			
		if (this.getCurrentTileIndex() > 0 && this.getCurrentTileIndex() < 4 ) {
			if (!isCheck) {
				isAttak = true;
				isCheck = true;
			}
		} 
		else if (this.getCurrentTileIndex() == 4) {
			if (this.getAlpha() > 0.05)
				this.setAlpha(getAlpha() - 0.008f);
		}
		
		super.onManagedUpdate(pSecondsElapsed);
	}
	
	@Override
	public boolean attack(final float pX, final float pY) {
		float xOffset = this.xGoal - pX;
		float yOffset = this.yGoal - pY;
		
		float offset = (float)(Math.sqrt(xOffset * xOffset + yOffset * yOffset));
		
		if (offset < 120 + this.mLevel * 8)
			return true;
		
		return false;
	}

	@Override
	public void complete() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public int getName() {
		return this.name;
	}

	@Override
	public boolean isAttack() {
		return isAttak;
	}

	public void stopInfluence() {
		this.isAttak = false;
	}

	@Override
	public float getDamge() {
		return damage;
	}

	@Override
	public void setDamage(float damage) {
		this.damage = damage;
	}

	@Override
	public float useMana() {
		return useMana;
	}

	@Override
	public void setMana(float mana) {
		this.useMana = mana;
	}

	@Override
	public long getStart() {
		return start;
	}

	@Override
	public void remove() {
		this.detachSelf();
	}

	@Override
	public BaseSprite returnSeft() {
		// TODO Auto-generated method stub
		return this;
	}
}
